<?php

namespace app\controllers;

use Yii;
use yii\web\Controller;
use app\models\RoleAccess;


class BaseAdminController extends Controller
{
   public function init()
   {
   		parent::init();
   }
   
   public function beforeAction($action)
   {
   		//判断用户是否登录
   		if(!Yii::$app->user->isGuest)
   		{
   		    $session = Yii::$app->session;
   		    
   		    $array_role = $session->get('array_role');
   		    
   		    $module = Yii::$app->controller->id;
   		    
   		    $action = Yii::$app->controller->action->id;
   		     		    
   		    if(!empty($array_role))
   		    {
   		        $have_role = false;
   		        foreach ($array_role as $key => $value)
   		        {
   		            if($value['module'] == $module && $value['action'] == $action)
   		            {
   		                $have_role = true;
   		                break;
   		            }else{
   		                continue;
   		            }
   		        }
   		    
   		        if($have_role === false)
   		        {
   		            return $this->redirect(['message/index'])->send();
   		        }else{
   		            return true;
   		        }
   		    }else{
   		        return $this->redirect(['message/index'])->send();
   		    }  
   		
   		   
   		}else{
   			//用户未登录跳转   			
   			return $this->redirect(['site/login'])->send();
   		}
   		
   }
  
}
